package com.ewuyong.concurrence;

import com.ewuyong.concurrence.example.threadlocal.RequestHolder;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Slf4j
public class HttpFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        log.info("do filter {}, {}", Thread.currentThread().getId(), httpServletRequest.getContextPath());
        RequestHolder.add(Thread.currentThread().getId());
        //继续后面的操作
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {

    }
}
